package leecode;

public class TwoNumber167 {

	public static void main(String[] args) {
		int[] resArr = new TwoNumber167().twoSum(new int[] { 2, 7, 11, 15 }, 9);
		System.out.println(resArr[0] + ", " + resArr[1]);
	}

	public int[] twoSum(int[] numbers, int target) {
		int[] result = { 0, 0 };

		for (int i = 0, k = numbers.length - 1; i < k;) {
			int sum = numbers[i] + numbers[k];
			if (sum == target) {
				result[0] = i + 1;
				result[1] = k + 1;
				break;
			} else if (sum < target) {
				i++;
			} else {
				k--;
			}
		}

		return result;
	}
}
